home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / NetMouse ƒ / NetMouse Xmt / ShowINIT.c < prev   
Encoding:
C/C++ Source or Header  |  1992-06-22  |  11.0 KB  |  348 lines  |  [TEXT/KAHL]

  1. #define ShowINIT foo
  2. #include "Misc.h"
  3. #undef ShowINIT
  4.  
  5. void ShowINIT(short iconID, short advance);
  6.  
  7. #if 0
  8. ; File: ShowINIT.a
  9. ; Last Modified: Sunday, November 26, 1989 05:07:56 PM
  10. ;------------------------------------------------------------------------------------------------
  11. ;
  12. ;    INIT notification routine
  13. ;     by Paul Mercer, Darin Adler, Paul Snively and Frédéric Miserey from an idea by Steve Capps
  14. ;
  15. ;    Created:  6/7/87  PM    - First version.
  16. ;    Modified: 6/15/87 PM    - Changed to standard (Pascal) calling conventions.
  17. ;          6/20/87 PM    - Fixed color & Finder bug on Mac II.
  18. ;          6/22/87 DBA    - Improved handling of QuickDraw.
  19. ;          6/29/87 DBA    - Used scratch8 to avoid conflict with “Easy Access”.
  20. ;          6/30/87 DBA    - Changed to a 4-byte scheme with “checksum”.
  21. ;          6/30/87 PFS    - Separated into ShowINIT and InnerShowINIT.
  22. ;          7/1/87  DBA    - Fixed stack bug and switched to CurApName+.
  23. ;          7/2/87  PM    - Added check for old signature in ApplScratch for
  24. ;                          backword compatibility (TMON Startup).
  25. ;          7/3/87  PM    - Removed _SysBeep in ErrorExit since it causes a crash.
  26. ;                          Also changed ICN# plotter to srcOr mode for Blinker.
  27. ;          7/13/87 PM    - Fixed a3 trashing bug in InnerShowINIT - exit code left
  28. ;                          word on stack (reported by D. Dunham).
  29. ;          7/21/87 PM    - Due to popular demand, InitGraf is no longer being called.
  30. ;                          This avoids the gamma correction problem with Startupscreens
  31. ;                          getting  “washed out” by ShowINIT though someone else is still
  32. ;                          bound to call InitGraf sooner or later (i.e. InitWindows).
  33. ;          7/29/87 PM    - Put InitGraf back in; this is required (reported by C. Derossi
  34. ;                          at Apple Tech Support).  Took out GetPort/SetPort.
  35. ;        10/06/87  PM    - Set CurrentA5 properly.  Rearranged myVars.
  36. ;        12/28/87  PM    - Major revision to accomodate future INIT31 based ShowINIT.
  37. ;        07/14/88  PM    - Major revision to get rid of above 'accomodations'.
  38. ;                          Added color icon 'cicn' support and fixed beep crash.
  39. ;                          Removed support for old signature.
  40. ;        11/25/89 FCM    - Added Y dimension support, icl48 support to get rid of 'obsolete' cicns
  41. ;         8/28/90 jbx    - Translated to Think C, added automatic x-movement determination.
  42. ;        6/22/92 jbx    - Cleaned up slightly from internal Now version for MacHack use.
  43. ;                         Also cleaned up interface to DrawAnIcon routine.
  44. ;------------------------------------------------------------------------------------------------
  45. #endif
  46.  
  47. /* Originally written by Paul Mercer.  Translated to Think C by jbx.  The latest ShowINIT
  48.    source is always up on AppleLink, so if there's a version there later than 11/25/89,
  49.    the version that added vertical wrap support, you should examine it for changes. */
  50.  
  51. typedef struct {
  52.     long    Icon[32];
  53.     long    IconMask[32];
  54. } ICONList, *ICONListPtr, **ICONListHdl;
  55.  
  56. extern short myVCheck    : 0x928;    /* a GREAT place to store 8 bytes (it was Darin's idea) */
  57. extern short myV        : 0x92A;
  58. extern short myH        : 0x92C;
  59. extern short myHCheck    : 0x92E;    /* a simple checksum of myH to determine first-timeness */
  60.  
  61. enum {
  62.     firstX            =    8,            /* X coordinate of first icon to be drawn        */
  63.     bottomEdge        =    8+32,        /* this far from bottom of screen                */
  64.     iconWidth        =    32,            /* size of icon (square normally)                */
  65.     defaultMoveX    =    40,            /* x default amount to move icons                */
  66.     defaultMoveY    =    40,            /* y icon line height                            */
  67.     checksumConst    =    0x1021,        /* constant used for computing checksum            */
  68.  
  69.     iconRowBytes    =    32/8,        /* 32/8 bits                                    */
  70.  
  71.     hasCQDBit        =    6            /* this bit in ROM85 is cleared if Color QuickDraw is available */
  72.  
  73. };
  74.  
  75. struct {
  76.     char    qd_privates[76];    /* known only to Apple and MacWEEK... */
  77.     long    qd_randSeed;
  78.     BitMap    qd_screenBits;
  79.     Cursor    qd_arrow;
  80.     Pattern    qd_dkGray;
  81.     Pattern    qd_ltGray;
  82.     Pattern    qd_gray;
  83.     Pattern    qd_black;
  84.     Pattern    qd_white;
  85.     GrafPtr    qd_thePort;
  86. } myqd;
  87.  
  88. #define thePort        myqd.qd_thePort
  89. #define white        myqd.qd_white
  90. #define black        myqd.qd_black
  91. #define gray        myqd.qd_gray
  92. #define ltGray        myqd.qd_ltGray
  93. #define dkGray        myqd.qd_dkGray
  94. #define arrow        myqd.qd_arrow
  95. #define screenBits    myqd.qd_screenBits
  96. #define randSeed    myqd.qd_randSeed
  97.  
  98. static long        saveA5;
  99. static long        localA5;
  100.  
  101. static Rect srcRect = {0,0,32,32};    /* for copybits */
  102. static Rect    destRect= {0,0,32,32};
  103.  
  104. static BitMap myBitMap = {
  105.     0,                /* address */
  106.     iconRowBytes,    /* rowBytes */
  107.     0,0,32,32        /* Rect */
  108. };
  109. static BitMap myMaskMap = {
  110.     0,                /* address */
  111.     iconRowBytes,    /* rowBytes */
  112.     0,0,32,32        /* Rect */
  113. };
  114. static GrafPort    myPort;
  115.  
  116. static short Advance;
  117.  
  118. static Rect Zero32 = {0, 0, 32, 32};
  119.  
  120. void DrawAnIcon(void *BlackAndWhiteIcon, void *ColorIcon, short iclDepth, Rect dstRect) {
  121.     ICONListPtr        iconPtr = BlackAndWhiteIcon;
  122.     PixMapHandle    pmh;
  123.     PixMapPtr        pmp;
  124.     void            *oldA4 = SetA4(&main);
  125.  
  126.     myBitMap.baseAddr  = (void *)iconPtr->Icon;
  127.     myBitMap.bounds = Zero32;
  128.     myMaskMap.baseAddr = (void *)iconPtr->IconMask;
  129.     myMaskMap.bounds = Zero32;
  130.  
  131.     if (!ColorIcon || !(pmh = NewPixMap())) {
  132.         CopyMask(&myBitMap, &myMaskMap, &theQDPort()->portBits, &Zero32, &Zero32, &dstRect);
  133.     } else {
  134.         HLock(pmh);
  135.         pmp = *pmh;
  136.         DisposHandle(pmp->pmTable);
  137.         pmp->pmTable = (CTabHandle) RGetResource('clut', iclDepth);
  138.         pmp->baseAddr = ColorIcon;
  139.         pmp->rowBytes = 0x8000 | (iclDepth * iconRowBytes);
  140.         pmp->bounds = srcRect;
  141.         pmp->pixelType = chunky;
  142.         pmp->pixelSize = iclDepth;
  143.         pmp->cmpCount = 1;
  144.         pmp->cmpSize = iclDepth;
  145.         
  146.         CopyMask(pmp, &myMaskMap, &theQDPort()->portBits, &Zero32, &Zero32, &dstRect);
  147.  
  148.         pmp->pmTable = (void *)NewHandle(0);
  149.         DisposPixMap(pmh);
  150.     }
  151.  
  152.     SetA4(oldA4);
  153. }
  154.  
  155. static void ShowINITCredits(void) {
  156.     asm {
  157.         dc.b    "ShowINIT by Paul Mercer"    ,0
  158.         dc.b    "Copyright 1987-1989"        ,0
  159.         dc.b    "Version of 11/25/89"        ,0
  160.         dc.b    "Modified by jbx 6/9/92"    ,0
  161.     };
  162. }
  163.  
  164. /***************************************************************************************\
  165. |                                                                                        |
  166. |    Initializes the world and sets up the drawing rectangle                                |
  167. |                                                                                        |
  168. \***************************************************************************************/
  169.  
  170. static void INITInit(void) {
  171.     asm {
  172.         move.l    CurrentA5,saveA5    ; PM 10/6 save host A5
  173.         lea        localA5,a5            ; PM7/21
  174.         move.l    a5,CurrentA5
  175.         pea        thePort                ; PM 10/6 use a5 reference instead of a6
  176.         InitGraf                    ; fixes color bug as per DA@ICOM
  177.         pea        myPort
  178.         OpenPort
  179.  
  180.         move.w    myV,d0            ; get my v var
  181.         rol.w    #1,d0            ; compare against checksum
  182.         eor.w    #checksumConst,d0
  183.         cmp.w    myVCheck,d0
  184.         beq.s    @ScratchVOK        ; checks, so go on test my h var
  185.  
  186.         move.w    myPort.portBits.bounds.bottom,d0 ; else initialize as first time
  187.         sub.w    #bottomEdge,d0
  188.         move    d0,myV
  189. ScratchVOK:
  190.         move.w    myH,d0            ; get my h var
  191.         rol.w    #1,d0            ; compare against checksum
  192.         eor.w    #checksumConst,d0
  193.         cmp.w    myHCheck,d0
  194.         beq.s    @ScratchHOK        ; checks, so go on
  195.         move    #firstX,myH        ; else initialize as first time
  196. ScratchHOK:
  197.         move.l    myV,d0            ; trickery - high word is V, lo word is H.
  198.  
  199.         move.w    d0,d1            ; get future position
  200.         add.w    #iconWidth,d1    ; compute future rect right
  201.         cmp.w    myPort.portBits.bounds.right,d1 ; compare to main screen right
  202.         blt.s    @DontChangeLine    ; smaller - do nothing
  203.  
  204.         move.w    myV,d0            ; decrement Y value
  205.         subi.w    #defaultMoveY,d0
  206.         move.w    d0,myV
  207.         move.w    #firstX,myH        ; set X to initial value
  208.  
  209.         move.l    myV,d0
  210. DontChangeLine:
  211.         lea        destRect,a0
  212.         move.l    d0,(a0)+
  213.         move.l    d0,(a0)
  214.     }
  215. }
  216.  
  217. /***************************************************************************************\
  218. |                                                                                        |
  219. |    Advances the icon drawing position and adjusts destRect                             |
  220. |                                                                                        |
  221. \***************************************************************************************/
  222.  
  223. static void MaskAdjust(void) {
  224.     short    ht, wd;
  225.  
  226.     destRect.bottom += (ht = myMaskMap.bounds.bottom - myMaskMap.bounds.top);
  227.     destRect.right  += (wd = myMaskMap.bounds.right  - myMaskMap.bounds.left);
  228.  
  229.     if (Advance) {
  230.         myH += wd + 8;
  231.     }
  232. }
  233.  
  234. /***************************************************************************************\
  235. |                                                                                        |
  236. |    Cleans up the work done by INITInit and advances the icon drawing position            |
  237. |                                                                                        |
  238. \***************************************************************************************/
  239.  
  240. static void INITCleanup(void) {
  241.     asm {
  242.         move.w    myH,d0            ; get current position
  243.         rol.w    #1,d0            ; recompute h checksum
  244.         eor.w    #checksumConst,d0
  245.         move.w    d0,myHCheck        ;  and save it
  246.  
  247.         move    myV,d0            ; same for v checksum
  248.         rol.w    #1,d0
  249.         eor.w    #checksumConst,d0
  250.         move.w    d0,myVCheck
  251.  
  252.         pea        myPort            ; *** (DBA) I think that QuickDraw leaves handles around.
  253.         ClosePort                ; *** (DBA) Too bad we can't get rid of them...
  254.  
  255.         move.l    saveA5,a5        ; PM 10/6 restore host A5
  256.         move.l    a5,CurrentA5
  257.     }
  258. }
  259.  
  260. /***************************************************************************************\
  261. |                                                                                        |
  262. |    Displays the ICN# (cicn when in 4 bit mode or higher) specified by iconID.            |
  263. |                                                                                        |
  264. |    PROCEDURE ShowINIT(iconID: Integer); EXTERNAL;                                        |
  265. |                                                                                        |
  266. |    pascal void ShowINIT(short iconID);                                                    |
  267. |        extern;                                                                            |
  268. |                                                                                        |
  269. \***************************************************************************************/
  270.  
  271. // jbx change: addec "advance" parameter for animating icons.  Call ShowINIT(ID) to
  272. // show an icon, and call ShowINIT(0, ID) to show it but not advance the drawing
  273. // position so that the next time you call ShowINIT it will draw over the one you
  274. // just drew.  If you're wondering why the advance parameter is done this way, it's
  275. // to keep compatibility with old code that just calls ShowINIT(-4064) etc.
  276.  
  277. void ShowINIT(short iconID, short advance) {
  278.     ICONListHdl    BWicon;
  279.     Handle        icon;
  280.     long        depth;
  281.     
  282.     short        oldmyH = myH;
  283.     short        oldmyHC = myHCheck;
  284.  
  285.     void        *oldA4 = SetA4(&main);
  286.  
  287.     INITInit();            /* initialize for drawing */
  288.  
  289.     Advance = 1;
  290.     if (iconID == 0) {
  291.         iconID = advance;
  292.         Advance = 0;
  293.     }
  294.  
  295.         // always try to get the black and white icon
  296.     BWicon = (void *)GetResource('ICN#', iconID);    // try to get the icon resource.
  297.     if (ROM85 <= 0x3FFF) { // try to get a color icon if CQD exists
  298.         depth = (**(**GetMainDevice()).gdPMap).pixelSize;
  299.         if (depth >= 4) {
  300.             if (BWicon) {
  301.                 if (depth > 8) depth = 8;    // depth is either 4 or 8 now.
  302.                 icon = GetResource('icl0' + depth, iconID);
  303.                 if (!icon) {
  304.                     depth = (4 + 8) - depth;
  305.                     icon = GetResource('icl0' + depth, iconID);
  306.                 }
  307.                 if (icon) {
  308.                     HLock(icon);
  309.                     HLock(BWicon);
  310.                     myMaskMap.baseAddr = (void *)(**BWicon).IconMask;
  311.                     MaskAdjust();
  312.                 
  313.                     DrawAnIcon(*BWicon, *icon, depth, destRect);
  314.                     ReleaseResource(icon);
  315.                     ReleaseResource(BWicon);
  316.                     goto success;
  317.                 }
  318.             }
  319.     
  320.                 // OK, try for a cicn.
  321.             if (icon = (void *)GetCIcon(iconID)) {
  322.                 myMaskMap = ((CIconHandle)icon)[0]->iconMask;
  323.                 myMaskMap.baseAddr = (void *)((CIconHandle)icon)[0]->iconMaskData;
  324.                 MaskAdjust();
  325.                 PlotCIcon(&destRect, icon);
  326.                 DisposCIcon(icon);
  327.                 goto success;
  328.             }
  329.         }
  330.     }
  331.  
  332.         // OK, try to use a black and white icon.
  333.     if (BWicon) {
  334.         HLock(BWicon);
  335.             myBitMap.baseAddr  = (void *)(**BWicon).Icon;
  336.             myMaskMap.baseAddr = (void *)(**BWicon).IconMask;
  337.         
  338.             MaskAdjust();
  339.         
  340.             CopyMask(&myBitMap, &myMaskMap, &myPort.portBits, &srcRect, &srcRect, &destRect);
  341.         ReleaseResource(BWicon);
  342.         goto success;
  343.     }
  344.  
  345. success:
  346.     INITCleanup();
  347.     SetA4(oldA4);
  348. }